package com.imaker.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

/**
 * 该类封装了对字符串进行相关的加密操作
 * @author mayonghua
 *
 */
public class EncryptHelper {

	// 获得md5散列值
	public static String MD5(String data) {
		String str = "";
		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(data.getBytes());
			str = new String(md5.digest());
//			将加密后的数据进行base64
			BASE64Encoder base64en = new BASE64Encoder();
			str = base64en.encode(str.getBytes());
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
	}

}
